﻿#region Copyright and License
/*==============================================================================
 *  Copyright (c) cndotnet.org Corporation.  All rights reserved.
 * ===============================================================================
 * This code and information is provided "as is" without warranty of any kind,
 * either expressed or implied, including but not limited to the implied warranties
 * of merchantability and fitness for a particular purpose.
 * ===============================================================================
 * Licensed under the GNU General Public License (GPL) v2
 * http://www.cndotnet.org/ezsocio
 * ==============================================================================*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CNdotnet.Ezsocio.DataEntities;
using CNdotnet.Ezsocio.BusinessObjects;
using CNdotnet.Ezsocio.DataProvider;
using CNdotnet.Ezsocio.Core.Service;
using CNdotnet.Ezsocio.BusinessInterfaces;

namespace CNdotnet.Ezsocio.BusinessServices
{
    /// <summary>
    /// The business service of module
    /// </summary>
    public class ModuleService : ServiceBase, IModuleService
    {
        #region IModuleService Members

        /// <summary>
        /// Gets the modules by user id.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <returns></returns>
        public List<ModuleContract> GetModulesByUserId(int userId)
        {
            List<Module> moduls = this.LoadRepository<IModuleRepository>().GetModules(userId);

            var query = from m in moduls
                        select new ModuleContract
                        {
                            ID = m.ID,
                            Name = m.Name,
                            User = ContextService.Current.User,
                            EntryPoint = m.EntryPoint,
                            DisplayName = m.DisplayName,
                            Description = m.Description,
                            Suppressible = m.Suppressible
                        };
            return query.ToList<ModuleContract>();
        }

        #endregion
    }
}